package it.tukano.swingdeco.filechooser;

import it.tukano.io.FileExt;
import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 * A file filter that checks the name of the file against a set of extensions
 * @author pgi
 */
public class ExtensionFileFilter extends FileFilter {
    private final String description;
    private final String[] extensions;

    /**
     * Instance initializer
     */
    public ExtensionFileFilter(String description, String... extensions) {
        this.description = description;
        this.extensions = extensions;
    }

    /**
     * True if the file is a directory or its name ends with a supported extension
     * @param f the file to check
     * @return true if the file can be accepted
     */
    @Override
    public boolean accept(File f) {
        return f.isDirectory() || new FileExt(f).hasExtension(extensions);
    }

    /**
     * Returns the description set during construction
     * @return the description of the file set
     */
    @Override
    public String getDescription() {
        return description;
    }
}
